.class Lcom/waiqin365/base/print/d;
.super Ljava/lang/Thread;


# instance fields
.field final synthetic a:Lcom/waiqin365/base/print/b;

.field private b:Landroid/bluetooth/BluetoothSocket;

.field private final c:Landroid/bluetooth/BluetoothDevice;


# direct methods
.method public constructor <init>(Lcom/waiqin365/base/print/b;Landroid/bluetooth/BluetoothDevice;)V
    .locals 4

    iput-object p1, p0, Lcom/waiqin365/base/print/d;->a:Lcom/waiqin365/base/print/b;

    invoke-direct {p0}, Ljava/lang/Thread;-><init>()V

    iput-object p2, p0, Lcom/waiqin365/base/print/d;->c:Landroid/bluetooth/BluetoothDevice;

    const/4 v0, 0x0

    :try_start_0
    invoke-static {}, Lcom/waiqin365/base/print/b;->i()Ljava/util/UUID;

    move-result-object v1

    invoke-virtual {p2, v1}, Landroid/bluetooth/BluetoothDevice;->createInsecureRfcommSocketToServiceRecord(Ljava/util/UUID;)Landroid/bluetooth/BluetoothSocket;
    :try_end_0
    .catch Ljava/io/IOException; {:try_start_0 .. :try_end_0} :catch_0

    move-result-object v0

    :goto_0
    iput-object v0, p0, Lcom/waiqin365/base/print/d;->b:Landroid/bluetooth/BluetoothSocket;

    return-void

    :catch_0
    move-exception v1

    const-string/jumbo v2, "BluetoothService"

    const-string/jumbo v3, "create() failed"

    invoke-static {v2, v3, v1}, Landroid/util/Log;->e(Ljava/lang/String;Ljava/lang/String;Ljava/lang/Throwable;)I

    goto :goto_0
.end method


# virtual methods
.method public cancel()V
    .locals 3

    :try_start_0
    iget-object v0, p0, Lcom/waiqin365/base/print/d;->b:Landroid/bluetooth/BluetoothSocket;

    invoke-virtual {v0}, Landroid/bluetooth/BluetoothSocket;->close()V
    :try_end_0
    .catch Ljava/io/IOException; {:try_start_0 .. :try_end_0} :catch_0

    :goto_0
    return-void

    :catch_0
    move-exception v0

    const-string/jumbo v1, "BluetoothService"

    const-string/jumbo v2, "close() of connect socket failed"

    invoke-static {v1, v2, v0}, Landroid/util/Log;->e(Ljava/lang/String;Ljava/lang/String;Ljava/lang/Throwable;)I

    goto :goto_0
.end method

.method public run()V
    .locals 4

    const-string/jumbo v0, "BluetoothService"

    const-string/jumbo v1, "BEGIN mConnectThread"

    invoke-static {v0, v1}, Landroid/util/Log;->i(Ljava/lang/String;Ljava/lang/String;)I

    const-string/jumbo v0, "ConnectThread"

    invoke-virtual {p0, v0}, Lcom/waiqin365/base/print/d;->setName(Ljava/lang/String;)V

    iget-object v0, p0, Lcom/waiqin365/base/print/d;->a:Lcom/waiqin365/base/print/b;

    invoke-virtual {v0}, Lcom/waiqin365/base/print/b;->d()Z

    :try_start_0
    iget-object v0, p0, Lcom/waiqin365/base/print/d;->b:Landroid/bluetooth/BluetoothSocket;

    invoke-virtual {v0}, Landroid/bluetooth/BluetoothSocket;->connect()V
    :try_end_0
    .catch Ljava/io/IOException; {:try_start_0 .. :try_end_0} :catch_0

    :goto_0
    iget-object v1, p0, Lcom/waiqin365/base/print/d;->a:Lcom/waiqin365/base/print/b;

    monitor-enter v1

    :try_start_1
    iget-object v0, p0, Lcom/waiqin365/base/print/d;->a:Lcom/waiqin365/base/print/b;

    const/4 v2, 0x0

    invoke-static {v0, v2}, Lcom/waiqin365/base/print/b;->a(Lcom/waiqin365/base/print/b;Lcom/waiqin365/base/print/d;)Lcom/waiqin365/base/print/d;

    monitor-exit v1
    :try_end_1
    .catchall {:try_start_1 .. :try_end_1} :catchall_0

    iget-object v0, p0, Lcom/waiqin365/base/print/d;->a:Lcom/waiqin365/base/print/b;

    iget-object v1, p0, Lcom/waiqin365/base/print/d;->b:Landroid/bluetooth/BluetoothSocket;

    iget-object v2, p0, Lcom/waiqin365/base/print/d;->c:Landroid/bluetooth/BluetoothDevice;

    invoke-virtual {v0, v1, v2}, Lcom/waiqin365/base/print/b;->a(Landroid/bluetooth/BluetoothSocket;Landroid/bluetooth/BluetoothDevice;)V

    :goto_1
    return-void

    :catch_0
    move-exception v0

    :try_start_2
    iget-object v0, p0, Lcom/waiqin365/base/print/d;->b:Landroid/bluetooth/BluetoothSocket;

    invoke-virtual {v0}, Landroid/bluetooth/BluetoothSocket;->getRemoteDevice()Landroid/bluetooth/BluetoothDevice;

    move-result-object v0

    invoke-virtual {v0}, Ljava/lang/Object;->getClass()Ljava/lang/Class;

    move-result-object v0

    const/4 v1, 0x1

    new-array v1, v1, [Ljava/lang/Class;

    const/4 v2, 0x0

    sget-object v3, Ljava/lang/Integer;->TYPE:Ljava/lang/Class;

    aput-object v3, v1, v2

    const-string/jumbo v2, "createRfcommSocket"

    invoke-virtual {v0, v2, v1}, Ljava/lang/Class;->getMethod(Ljava/lang/String;[Ljava/lang/Class;)Ljava/lang/reflect/Method;

    move-result-object v0

    const/4 v1, 0x1

    new-array v1, v1, [Ljava/lang/Object;

    const/4 v2, 0x0

    const/4 v3, 0x1

    invoke-static {v3}, Ljava/lang/Integer;->valueOf(I)Ljava/lang/Integer;

    move-result-object v3

    aput-object v3, v1, v2

    iget-object v2, p0, Lcom/waiqin365/base/print/d;->b:Landroid/bluetooth/BluetoothSocket;

    invoke-virtual {v2}, Landroid/bluetooth/BluetoothSocket;->getRemoteDevice()Landroid/bluetooth/BluetoothDevice;

    move-result-object v2

    invoke-virtual {v0, v2, v1}, Ljava/lang/reflect/Method;->invoke(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;

    move-result-object v0

    check-cast v0, Landroid/bluetooth/BluetoothSocket;

    iput-object v0, p0, Lcom/waiqin365/base/print/d;->b:Landroid/bluetooth/BluetoothSocket;

    const-wide/16 v0, 0x1f4

    invoke-static {v0, v1}, Ljava/lang/Thread;->sleep(J)V

    iget-object v0, p0, Lcom/waiqin365/base/print/d;->b:Landroid/bluetooth/BluetoothSocket;

    invoke-virtual {v0}, Landroid/bluetooth/BluetoothSocket;->connect()V
    :try_end_2
    .catch Ljava/lang/Exception; {:try_start_2 .. :try_end_2} :catch_1

    goto :goto_0

    :catch_1
    move-exception v0

    invoke-virtual {v0}, Ljava/lang/Exception;->printStackTrace()V

    iget-object v0, p0, Lcom/waiqin365/base/print/d;->a:Lcom/waiqin365/base/print/b;

    invoke-static {v0}, Lcom/waiqin365/base/print/b;->c(Lcom/waiqin365/base/print/b;)V

    :try_start_3
    iget-object v0, p0, Lcom/waiqin365/base/print/d;->b:Landroid/bluetooth/BluetoothSocket;

    invoke-virtual {v0}, Landroid/bluetooth/BluetoothSocket;->close()V
    :try_end_3
    .catch Ljava/io/IOException; {:try_start_3 .. :try_end_3} :catch_2

    :goto_2
    iget-object v0, p0, Lcom/waiqin365/base/print/d;->a:Lcom/waiqin365/base/print/b;

    invoke-virtual {v0}, Lcom/waiqin365/base/print/b;->h()V

    goto :goto_1

    :catch_2
    move-exception v0

    const-string/jumbo v1, "BluetoothService"

    const-string/jumbo v2, "unable to close() socket during connection failure"

    invoke-static {v1, v2, v0}, Landroid/util/Log;->e(Ljava/lang/String;Ljava/lang/String;Ljava/lang/Throwable;)I

    goto :goto_2

    :catchall_0
    move-exception v0

    :try_start_4
    monitor-exit v1
    :try_end_4
    .catchall {:try_start_4 .. :try_end_4} :catchall_0

    throw v0
.end method
